      SUBROUTINE AIRDRG(ITEST)
C
      IMPLICIT REAL*8(A-H,O-Z)
C
      REAL*8 J2,J3,J4,J22,METERS
C
      COMMON/CENVRN/ GGMOM(3),SPMOM(3),ADMOM(3),HUBSPM(3),HUBADM(3)
C
      COMMON/CNBODY/ J2,J3,J4,J22,ZJ20,ZMU,WWO,FLAT,AEARTH
C
      COMMON/DEBUG2/ IOUT,JOUT,KLUGE
C
      COMMON/DRGCOM/ ER(3),HUBCDA(3),HUBCP(3),UJD0,HUBF(3),HUBM(3),IDRAG
C
      COMMON/DRPROT/ STAGP,RMAG,UNADR(3)
C
      COMMON/RPOOL1/ RHOK(10),TIME,DUM(113)
C
      COMMON/RPOOL2/ PO,SD(3),DAN(3,10),DBN(3,10),CFMT(3,3),DIY1(3),
     .               SD1(3),DT1,P1,AERO,DTO1,YIZK(3),PO1
C
      COMMON/RPOOL6/ FM(3,3),CIY(3,3),CIZ(3,3),SAT(3,3),SZ1,SZ2,SZ3
C
      COMMON/SUNVTR/ SLB(3)
C
      COMMON/VECTRS/ XSAT(3),XSATDT(3),AD(3)
C
      DIMENSION USAT(3),USUN(3),VAT(3),HUBAD(3),HUBSP(3)
C
      DATA METERS/3.28083333333333D3/,RHZERO/0.0019399774D0/
C
      DATA ESQ/6.69454D-3/
C
C
      RSQ=XSAT(1)*XSAT(1)+XSAT(2)*XSAT(2)+XSAT(3)*XSAT(3)
      RMAG=DSQRT(RSQ)
C
      IF(RMAG.LT.1.0D-6) RMAG=1.0D-6
      UNADR(1)=-XSAT(1)/RMAG
      UNADR(2)=-XSAT(2)/RMAG
      UNADR(3)=-XSAT(3)/RMAG
C
C     CALCULATE HEIGHT OF SPACECRAFT
C
      H=RMAG-AEARTH
C
C     IDRAG 1 STANDARD 1962 ATMOS. - IDRAG 2 JACCHIA ROBERTS MODEL
C
      IF(IDRAG.GT.1) GO TO 15
      H=H*METERS
      CALL ATMO62(H,RHO,ASOUND,TEMP,PRES)
C
      GO TO 50
C
   15 CONTINUE
      DO 20 I=1,3
      USAT(I)=XSAT(I)/RMAG
      USUN(I)=-SD(I)
   20 CONTINUE
C
      T=UJD0+TIME/86400.0D0
C
      CALL JACROB(ESQ,H,T,USAT,USUN,RHO)
C
C     JACROB GIVES DENSITY IN KG/KM**3
      RHO=RHO*1.0D-9
C
   50 CONTINUE
      RHO1=RHO*RHZERO
C
C     CALCULATE RELATIVE VELOCITY OF ATMOSPHERE TO VEHICLE
C
      VAT(1)=XSATDT(1)+XSAT(2)*ER(3)-XSAT(3)*ER(2)
      VAT(2)=XSATDT(2)+XSAT(3)*ER(1)-XSAT(1)*ER(3)
      VAT(3)=XSATDT(3)+XSAT(1)*ER(2)-XSAT(2)*ER(1)
C
      VSQ=VAT(1)*VAT(1)+VAT(2)*VAT(2)+VAT(3)*VAT(3)
      VMAG=DSQRT(VSQ)
C
      STAGP=0.5D0*RHO1*VSQ*METERS*METERS
      P1=STAGP*AERO
C
      IF(ITEST.EQ.2) GO TO 100
C
      DO 55 I=1,3
      SD1(I)=-VAT(I)/VMAG
   55 CONTINUE
C
C     TRANSFORM FLOW VECTOR TO BODY FRAME
C
      DO 56 I=1,3
      DIY1(I)=SAT(I,1)*SD1(1)+SAT(I,2)*SD1(2)+SAT(I,3)*SD1(3)
   56 CONTINUE
C
C     CALCULATE HUB DRAG FORCE AND MOMENT
C
      DO 60 I=1,3
      HUBF(I)=HUBCDA(I)*(STAGP*DIY1(I)+PO*SLB(I))
      HUBAD(I)=HUBCDA(I)*STAGP*DIY1(I)
      HUBSP(I)=HUBCDA(I)*PO*SLB(I)
   60 CONTINUE
C
      HUBM(1)=HUBF(3)*HUBCP(2)-HUBF(2)*HUBCP(3)
      HUBADM(1)=HUBAD(3)*HUBCP(2)-HUBAD(2)*HUBCP(3)
      HUBSPM(1)=HUBSP(3)*HUBCP(2)-HUBSP(2)*HUBCP(3)
      HUBM(2)=HUBF(1)*HUBCP(3)-HUBF(3)*HUBCP(1)
      HUBADM(2)=HUBAD(1)*HUBCP(3)-HUBAD(3)*HUBCP(1)
      HUBSPM(2)=HUBSP(1)*HUBCP(3)-HUBSP(3)*HUBCP(1)
      HUBM(3)=HUBF(2)*HUBCP(1)-HUBF(1)*HUBCP(2)
      HUBADM(3)=HUBAD(2)*HUBCP(1)-HUBAD(1)*HUBCP(2)
      HUBSPM(3)=HUBSP(2)*HUBCP(1)-HUBSP(1)*HUBCP(2)
C
  100 CONTINUE
C
      IF(IOUT.NE.1) WRITE(6,6012) IDRAG,RHO,P1,STAGP
 6012 FORMAT(' **AIRDRG** ',I2,1P3E14.6)
C
      RETURN
C
      END
